home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src / masking.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-13  |  4.9 KB  |  192 lines

  1. /* $Id: masking.c,v 1.3 1996/11/06 04:19:40 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.1
  6.  * Copyright (C) 1995-1996  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: masking.c,v $
  26.  * Revision 1.3  1996/11/06 04:19:40  brianp
  27.  * now call gl_read_color/index_span() instead of device driver function
  28.  *
  29.  * Revision 1.2  1996/10/25 00:07:46  brianp
  30.  * changed MAX_WIDTH to PB_SIZE in gl_mask_index_pixels()
  31.  *
  32.  * Revision 1.1  1996/09/13 01:38:16  brianp
  33.  * Initial revision
  34.  *
  35.  */
  36.  
  37.  
  38. /*
  39.  * Implement the effect of glColorMask and glIndexMask in software.
  40.  */
  41.  
  42.  
  43.  
  44. #include <string.h>
  45. #include "alphabuf.h"
  46. #include "context.h"
  47. #include "macros.h"
  48. #include "masking.h"
  49. #include "pb.h"
  50. #include "span.h"
  51. #include "types.h"
  52.  
  53.  
  54.  
  55. void gl_IndexMask( GLcontext *ctx, GLuint mask )
  56. {
  57.    if (INSIDE_BEGIN_END(ctx)) {
  58.       gl_error( ctx, GL_INVALID_OPERATION, "glIndexMask" );
  59.       return;
  60.    }
  61.    ctx->Color.IndexMask = mask;
  62.    ctx->NewState |= NEW_RASTER_OPS;
  63. }
  64.  
  65.  
  66.  
  67. void gl_ColorMask( GLcontext *ctx, GLboolean red, GLboolean green,
  68.                    GLboolean blue, GLboolean alpha )
  69. {
  70.    if (INSIDE_BEGIN_END(ctx)) {
  71.       gl_error( ctx, GL_INVALID_OPERATION, "glColorMask" );
  72.       return;
  73.    }
  74.    ctx->Color.ColorMask = (red << 3) | (green << 2) | (blue << 1) | alpha;
  75.    ctx->NewState |= NEW_RASTER_OPS;
  76. }
  77.  
  78.  
  79.  
  80.  
  81. /*
  82.  * Apply glColorMask to a span of RGBA pixels.
  83.  */
  84. void gl_mask_color_span( GLcontext *ctx,
  85.                          GLuint n, GLint x, GLint y,
  86.                          GLubyte red[], GLubyte green[],
  87.                          GLubyte blue[], GLubyte alpha[] )
  88. {
  89.    GLubyte r[MAX_WIDTH], g[MAX_WIDTH], b[MAX_WIDTH], a[MAX_WIDTH];
  90.  
  91.    gl_read_color_span( ctx, n, x, y, r, g, b, a );
  92.  
  93.    if ((ctx->Color.ColorMask & 8) == 0) {
  94.       /* replace source reds with frame buffer reds */
  95.       MEMCPY( red, r, n );
  96.    }
  97.    if ((ctx->Color.ColorMask & 4) == 0) {
  98.       /* replace source greens with frame buffer greens */
  99.       MEMCPY( green, g, n );
  100.    }
  101.    if ((ctx->Color.ColorMask & 2) == 0) {
  102.       /* replace source blues with frame buffer blues */
  103.       MEMCPY( blue, b, n );
  104.    }
  105.    if ((ctx->Color.ColorMask & 1) == 0) {
  106.       /* replace source alphas with frame buffer alphas */
  107.       MEMCPY( alpha, a, n );
  108.    }
  109. }
  110.  
  111.  
  112.  
  113. /*
  114.  * Apply glColorMask to an array of RGBA pixels.
  115.  */
  116. void gl_mask_color_pixels( GLcontext *ctx,
  117.                            GLuint n, const GLint x[], const GLint y[],
  118.                            GLubyte red[], GLubyte green[],
  119.                            GLubyte blue[], GLubyte alpha[],
  120.                            const GLubyte mask[] )
  121. {
  122.    GLubyte r[PB_SIZE], g[PB_SIZE], b[PB_SIZE], a[PB_SIZE];
  123.  
  124.    (*ctx->Driver.ReadColorPixels)( ctx, n, x, y, r, g, b, a, mask );
  125.    if (ctx->RasterMask & ALPHABUF_BIT) {
  126.       gl_read_alpha_pixels( ctx, n, x, y, a, mask );
  127.    }
  128.  
  129.    if ((ctx->Color.ColorMask & 8) == 0) {
  130.       /* replace source reds with frame buffer reds */
  131.       MEMCPY( red, r, n );
  132.    }
  133.    if ((ctx->Color.ColorMask & 4) == 0) {
  134.       /* replace source greens with frame buffer greens */
  135.       MEMCPY( green, g, n );
  136.    }
  137.    if ((ctx->Color.ColorMask & 2) == 0) {
  138.       /* replace source blues with frame buffer blues */
  139.       MEMCPY( blue, b, n );
  140.    }
  141.    if ((ctx->Color.ColorMask & 1) == 0) {
  142.       /* replace source alphas with frame buffer alphas */
  143.       MEMCPY( alpha, a, n );
  144.    }
  145. }
  146.  
  147.  
  148.  
  149. /*
  150.  * Apply glIndexMask to a span of CI pixels.
  151.  */
  152. void gl_mask_index_span( GLcontext *ctx,
  153.                          GLuint n, GLint x, GLint y, GLuint index[] )
  154. {
  155.    GLuint i;
  156.    GLuint fbindexes[MAX_WIDTH];
  157.    GLuint msrc, mdest;
  158.  
  159.    gl_read_index_span( ctx, n, x, y, fbindexes );
  160.  
  161.    msrc = ctx->Color.IndexMask;
  162.    mdest = ~msrc;
  163.  
  164.    for (i=0;i<n;i++) {
  165.       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
  166.    }
  167. }
  168.  
  169.  
  170.  
  171. /*
  172.  * Apply glIndexMask to an array of CI pixels.
  173.  */
  174. void gl_mask_index_pixels( GLcontext *ctx,
  175.                            GLuint n, const GLint x[], const GLint y[],
  176.                            GLuint index[], const GLubyte mask[] )
  177. {
  178.    GLuint i;
  179.    GLuint fbindexes[PB_SIZE];
  180.    GLuint msrc, mdest;
  181.  
  182.    (*ctx->Driver.ReadIndexPixels)( ctx, n, x, y, fbindexes, mask );
  183.  
  184.    msrc = ctx->Color.IndexMask;
  185.    mdest = ~msrc;
  186.  
  187.    for (i=0;i<n;i++) {
  188.       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
  189.    }
  190. }
  191.  
  192.